Description:
In the case of an exception, an object will not be released
if a method is placed in a finally block in one piece of the code but
is also used outside of the finally clause in some places where
an exception can also be raised.
ONF does not understand the semantics of the method and cannot determine whether
the method is really releasing or closing some resource, but if it is used somewhere
inside of a finally block, then it means that invocation of this method
is critical and should be done in any case. Therefore, if in some other place where
exceptions are also possible (the method is declared as throwing some exception or
it is a statement in a try block), and the method is used outside of the finally block,
it can be an error.
Incorrect:
void read(IResource resource, char[] buf) {
resource.open();
try {
...
} finally {
resource.close();
}
}
void write(IResource resource, char[] buf) {
resource.open();
...
resource.close();
}
Correct:
void write(IResource resource, char[] buf) {
try {
...
} finally {
resource.close();
}
}